package com.whkjdx.examtool.web;

import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil;
import com.whkjdx.examtool.entity.HandshakeRequest;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author: xucong
 * @Date: 13:38 2022/2/11
 * @Description:
 * @Version v1.0
 */
@RestController
public class MythController {


    @RequestMapping(value = "/handshake",method = {RequestMethod.POST},produces = "text/html; charset=utf-8")
    String handshake(@RequestBody HandshakeRequest request){
        List<String> skinList = new ArrayList<>();
        skinList.add("monkey_king_horse");
        skinList.add("monkey_king_sea");
        skinList.add("monkey_king_fire");
        skinList.add("monkey_king_opera");
        skinList.add("monkey_king_ear");
        skinList.add("monkey_king_wine");
        skinList.add("yangjian_black");
        skinList.add("yangjian_dao");
        skinList.add("yangjian_gold");
        skinList.add("yangjian_hawk");
        skinList.add("white_bone_white");
        skinList.add("white_bone_opera");
        skinList.add("white_bone_queen");
        skinList.add("pigsy_marry");
        skinList.add("pigsy_white");
        skinList.add("pigsy_constellation");
        skinList.add("myth_yutu_frog");
        skinList.add("myth_yutu_winter");
        skinList.add("myth_yutu_apricot");
        skinList.add("myth_yutu_laurel");
        skinList.add("myth_yutu_soprano");
        skinList.add("neza_green");
        skinList.add("neza_pink");
        skinList.add("neza_fire");
        skinList.add("neza_rap");
        skinList.add("yama_commissioners_lotus");
        skinList.add("madameweb_rat");

        StringBuilder sb = new StringBuilder();
        sb.append("<LW>");
        sb.append(JSONUtil.toJsonStr(skinList));
        sb.append("</LW>");
        sb.append("<SKIN>");
        sb.append(JSONUtil.toJsonStr(skinList));
        sb.append("</SKIN>");
        sb.append("<ACTIVITY>7011</ACTIVITY>");
        sb.append("<ALLSKIN>");
        Map<String,List<String>> allSkin = new HashMap<>();
        for (String s : request.getPlayerlist()) {
            allSkin.put(s,skinList);
        }
        sb.append(JSONUtil.toJsonStr(allSkin));
        sb.append("</ALLSKIN>");


        HttpRequest post = HttpUtil.createPost("http://myth.flapi.cn:90/handshake/");
        post.body(JSONUtil.toJsonStr(request));
        post.executeAsync();
        return sb.toString();
    }

    @PostMapping("/puttest")
    public String puttest(@RequestParam String name){
        return name;
    }
}
